
import { userinfoT } from './interface';
import { localeStore } from './index';

// 用户信息
export const getUserInfo = () => {
	let param = localStorage.getItem('userInfo');
	if (param === null) {
		return localeStore.userInfo;
	} else {
		return JSON.parse(param);
	}
};

export const setUserInfo = (param: userinfoT) => {
	for (let i in param) {
		localeStore.userInfo[i] = param[i];
	}
	localStorage.setItem('userInfo', JSON.stringify(param));
};

/**
 * @name: 获取本地token
 * @Description: 函数说明
 * @return {string} 获取localStorage中authorization无则返回空字符
 */
export const getToken = () => {
	let param = localStorage.getItem('authorization');
	if (param === null) {
		return '';
	} else {
		return param;
	}
};
export const setToken = (param: string) => {
	localeStore.authorization = param;
	localStorage.setItem('authorization', param);
};

/**
 * @Author: 刘强
 * @description: 用户是否初始化应用
 * @param {*}
 * @return {*}
 */
export const getGuide = () => {
	let param = localStorage.getItem('guideUser');
	if (param === null) {
		return '';
	} else {
		return param;
	}
};
export const setGuide = (param) => {
	localeStore.guideUser = param;
	localStorage.setItem('guideUser', param);
};

/**
 * @Author: 刘强
 * @description: 用户是否显示公告
 * @param {*}
 * @return {*}
 */
export const getNotice = () => {
	let param = localStorage.getItem('noticeVisible');
	if (param === null) {
		return true;
	} else {
		return JSON.parse(param);
	}
};
export const setNotice = (param) => {
	localeStore.noticeVisible = param;
	localStorage.setItem('noticeVisible', JSON.stringify(param));
};
/**
 * @Author: 刘强
 * @description: 本地临时存储日志信息队列
 * @param {*}
 * @return {*}
 */
export const getLogList = () => {
	let param = localStorage.getItem('logList');
	if (param === null) {
		return localeStore.logList;
	} else {
		return JSON.parse(param);
	}
};
export const setLogList = (param) => {
	localeStore.logList = [...param];
	localStorage.setItem('logList', JSON.stringify(param));
};

/**
 * @Author: 刘强
 * @description: 虚拟头像背景色-随机队列
 * @param {*}
 * @return {*}
 */
export const getPortraitBgColor = () => {
	let param = localStorage.getItem('portraitBgColor');
	if (param === null) {
		return -1;
	} else {
		return JSON.parse(param);
	}
};
export const setPortraitBgColor = (param) => {
	localeStore.portraitBgColor = param;
	localStorage.setItem('portraitBgColor', JSON.stringify(param));
};

/**
 * @Author: 刘强
 * @description: 背景替换-激活项
 * @param {* portraitBgColor}
 * @return {*}
 */
export const getReplaceBgActive = () => {
	let param = localStorage.getItem('replaceBgActive');
	if (param === null) {
		return 0;
	} else {
		return JSON.parse(param);
	}
};
export const setReplaceBgActive = (param) => {
	localeStore.replaceBgActive = param;
	localStorage.setItem('replaceBgActive', JSON.stringify(param));
};
